<template>
	<div>
		<el-container>
			<!-- 头部容器 -->
			<el-header>
				<div class="title_box">
					<img src="../assets/logo.png" alt="">
					<span>电商后台管理系统</span>
				</div>
				<el-button class="logout_btn" type="info" @click="logout">退出</el-button>
			</el-header>
			<!-- 页面区域 -->
			<el-container>
				<!-- 侧边导航 -->
				<el-aside :width="isCollapse?'64px':'200px'">
					<div class="toggle_btn" @click="changeMenuStyle">|||</div>
					<el-menu default-active="2" router unique-opened :collapse="isCollapse" :collapse-transition="false"
						class="el-menu-vertical-demo" background-color="#333744" text-color="#fff">
						<el-submenu :index="item.id+''" v-for="item in menusList" :key="item.id">
							<template slot="title">
								<i :class="'icon iconfont '+iconObj[item.id]"></i>
								<span>{{item.authName}}</span>
							</template>
							<el-menu-item v-for="it in item.children" :key="it.id" :index="'/'+it.path">
								<i class="el-icon-menu"></i>
								<span>{{ it.authName }}</span>
							</el-menu-item>
						</el-submenu>
					</el-menu>
				</el-aside>
				<el-main>
					<router-view></router-view>
				</el-main>
			</el-container>
		</el-container>
	</div>
</template>

<script>
	export default {
		created() {
			this.getMenusList()
		},
		data() {
			return {
				isCollapse: false,
				menusList: [],
				iconObj: {
					"125": "icon-user",
					"103": "icon-tijikongjian",
					"101": "icon-shangpin",
					"102": "icon-danju",
					"145": "icon-baobiao"
				}
			}
		},
		methods: {
			changeMenuStyle() {
				this.isCollapse = !this.isCollapse
			},
			async getMenusList() {
				let {
					data: res
				} = await this.$http.get("menus");
				console.log(res);
				//报错处理
				if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
				//成功后把数据放到data中
				this.menusList = res.data;
			},
			logout() {
				window.sessionStorage.clear()
				this.$router.push("/login")
			}
		}
	}
</script>

<style lang="scss" scoped>
	.el-container {
		height: 100vh;
	}

	.el-header {
		background-color: #373d41;

		.title_box {
			float: left;
			margin-left: 20px;
			text-align: center;
			height: 60px;
			line-height: 60px;

			img {
				display: inline-block;
				width: 60px;
				height: 60px;
				vertical-align: middle;
			}

			span {
				height: 60px;
				line-height: 60px;
				font-size: 22px;
				color: #fff;
				margin-left: 30px;
			}
		}

		.logout_btn {
			float: right;
			margin-right: 20px;
			margin-top: 10px
		}
	}

	.el-container {
		height: 100%;
	}

	.el-aside {
		// min-height: calc(100vh - 60px); 
		// height: 100%;
		background-color: #373d41;

		.toggle_btn {
			height: 24px;
			line-height: 24px;
			text-align: center;
			font-size: 10px;
			cursor: pointer;
			color: #ffffff;
			letter-spacing: 2px;
			background-color: #4a5064;
		}

		.el-menu {
			border-right: none;
		}

		.iconfont {
			margin-right: 20px;
		}
	}

	.el-main {
		min-height: calc(100vh - 60px);
		height: 100%;
		background-color: #eaedf1;
		// overflow: none;
	}
</style>
